﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BooksManagermentSystem
{
    public partial class Pay_form : Form
    {
        public Pay_form()
        {
            InitializeComponent();
        }

        private void Pay_form_Load(object sender, EventArgs e)
        {
            button2.Enabled= false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string stuid = textBox1.Text.Trim();
            if(stuid.Length == 0 )
            {
                MessageBox.Show("请输入学号！");
                textBox1.Focus();
                return;
            }

            string sql = $"select arrearage from StuInfo where stuid = '{stuid}'";

            DataRow dr = DBhelper.GetDataRow(sql);
            if(dr != null)
            {
                if (float.Parse(dr["arrearage"].ToString()) == 0)
                {
                    label3.Text = "不需要缴纳费用";
                }
                else
                {
                    label3.Text = dr["arrearage"].ToString() + "元";
                    button2.Enabled = true;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string stuid = textBox1.Text.Trim();
            string sql = $"update StuInfo set arrearage = 0 where stuid='{stuid}'";
            if(DBhelper.NonQuery(sql))
            {
                MessageBox.Show("缴费成功！");
                textBox1.Focus();
            }
        }
    }
}
